package com.example.teamtribe.main.club.clubintroduce.media.photo;

import android.os.Bundle;
import android.util.Log;

import com.example.teamtribe.common.Back;
import com.example.teamtribe.common.CallbackStore;
import com.example.teamtribe.json.JsonIds;
import com.example.teamtribe.utils.HttpUtil;
import com.example.teamtribe.utils.URLStore;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by lenovo on 2018/6/20.
 */

public class PhotoModel {
    public void addPhoto(String token, int teamId, String fileName, int albumId ,final Back back) {
        Map<String, String> params = new HashMap<>();
        params.put("TeamTribeToken", token);
        params.put("teamId", teamId+"");
        params.put("fileName", fileName);
        params.put("albumId", albumId+"");
        HttpUtil.post(URLStore.TEAM_PHOTO_ADD, params, CallbackStore.getCallback(back));
    }
    public void getPhotoNames(final int teamId, int albumId,int offset,int num,final Back back) {
        Map<String, String> params = new HashMap<>();
        params.put("teamId", teamId + "");
        params.put("albumId", albumId + "");
        params.put("offset", offset + "");
        params.put("num", num + "");
        HttpUtil.post(URLStore.TEAM_PHOTO_GET, params, new CallbackStore.CallbackImpl<Back>(back) {
            @Override
            public void onResponse(String json) {
                Log.d("多媒体", json);
                JsonIds jsonFilenames = new Gson().fromJson(json, JsonIds.class);
                ArrayList<String> fileNames=jsonFilenames.getFiles();
                Bundle b = new Bundle();
                b.putStringArrayList("fileNames",fileNames);
                back.success(b);
            }
        });
    }
//    public void getPhoto(final String photoName, final FileModel.FileBack back) {
//        Map<String, String> params = new HashMap<>();
//        params.put("albumId", mediaId + "");
//        HttpUtil.post(URLStore.TEAM_MEDIAINFO_GET, params, new CallbackStore.CallbackImpl<FileModel.FileBack>(back) {
//            @Override
//            public void onResponse(String json) {
//                Log.d("多媒体", json);
//                JsonMedia jsonMedia = new Gson().fromJson(json, JsonMedia.class);
//                final int status = jsonMedia.getCode();
//                if (status != 0) {
//                    back.failure(HttpUtil.getCodeMeg(status));
//                } else {
//                    final Media media = jsonMedia.getMedia();
//                    Bundle b = new Bundle();
//                    b.putParcelable("media", media);
//                    back.success(b);
//                    FileModel.getInstance().download(media.getCover(), 0, back);
//                }
//            }
//        });
//    }
}
